package models

type TerminalCar struct {
	Id           int64  `xorm:"not null pk autoincr INT(11)"`
	TerminalId   int64  `xorm:"not null comment('终端编号') unique INT(11)"`
	CarId        int64  `xorm:"not null comment('教练车编号') unique INT(11)"`
	Sim          string `xorm:"not null comment('终端SIM卡号') unique VARCHAR(16)"`
	RecordStatus string `xorm:"default '1' comment('1:已绑定2 解绑定') ENUM('1','2')"`
	Reged        string `xorm:"not null default '0' comment('设备是否鉴权 0未鉴权 1 已鉴权') ENUM('0','1')"`
	Remark       string `xorm:"VARCHAR(255)"`
	Iswuhan      string `xorm:"ENUM('0','1')"`
}

func (t *TerminalCar) CancelTerminal(id string) bool {
	_, err := engine.Exec("update dts_terminal_car set reged = ? where terminal_id = ?", "0", id)
	return err == nil
}

func (t *TerminalCar) GetOneTerminalCarByTerminalId(id string) (list TerminalCar, err error) {
	temp := new(TerminalCar)
	_, err = engine.Table("dts_terminal_car").
		Where("terminal_id = ?", id).
		Get(temp)
	return *temp, err
}
